1. What does the null character "\0" represent in a string in C?
Correct Answer: (B) The end of the string.
2. Which function is used to find the length of a string in C?
Correct Answer: (A) strlen().
3. What is the return value of the strlen() function when applied to an empty string?
Correct Answer: (C) 0.
4. Which function is used to copy one string to another in C?
Correct Answer: (B) strcpy().
5. Which function is used to concatenate two strings in C?
Correct Answer: (C) strcat().
6. What is the return value of strcmp() if two strings are identical?
Correct Answer: (A) 0.
7. Which header file is required for using string functions like strlen(), strcpy(), and strcmp()?
Correct Answer: (C) string.h.
8. If char s1[] = "hello"; and char s2[] = "world";, what does strcat(s1, s2); do?
Correct Answer: (B) Combines the two strings and stores them in s1.
9. Which of the following string functions compares two strings lexicographically?
Correct Answer: (C) strcmp().
10. If char s1[] = "abc"; and char s2[] = "ABC";, what does strcmp(s1, s2); return?
Correct Answer: (C) Negative integer.
11. Which function can be used to safely copy a specified number of characters from one string to another?
Correct Answer: (A) strncpy().
12. What does the strcmp() function return if the first string is lexicographically smaller than the second?
Correct Answer: (D) A negative integer.
13. What will strlen("hello world") return?
Correct Answer: (B) 11.
14. Which of the following strings will be stored correctly in memory?
Correct Answer: (D) Both (A) and (B).
15. Which function can be used to append a specific number of characters from one string to another?
Correct Answer: (A) strncat().
16. What does strcpy() do with the null terminator \0 when copying a string?
Correct Answer: (B) Copies it.
17. What is the output of strcmp("apple", "banana")?
Correct Answer: (C) Negative integer.
18. In C, strings are stored as arrays of characters terminated by which character?
Correct Answer: (B) '\0'.
19. Which of the following functions is not used for string comparison?
Correct Answer: (C) strcpy().
20. What will the function strcmp("apple", "apple") return?
Correct Answer: (C) 0.
21. Which function is used for string concatenation in C?
Correct Answer: (B) strcat().
22. What does the strcat() function do?
Correct Answer: (C) Appends one string to another.
23. What is the correct syntax of the strcat() function?
Correct Answer: (B) char* strcat(char* dest, const char* src).
24. What will strlen("Hello World") return?
Correct Answer: (A) 11.
25. Which header file is needed for string functions like strcpy() and strlen()?
Correct Answer: (C) string.h.
26. Which function is used to copy one string to another in C?
Correct Answer: (A) strcpy().
27. Which function is used to determine the length of a string in C?
Correct Answer: (C) strlen().
28. In strcat(), the source string is:
Correct Answer: (B) Appended to the destination string.
29. What does the strlen() function return?
Correct Answer: (B) Length of the string excluding the null character.
30. If char str[] = "C language";, what will strlen(str) return?
Correct Answer: (C) 11.
31. What is the output of strcpy(dest, src) if dest has a size smaller than src?
Correct Answer: (B) Causes undefined behavior.
32. Which function compares two strings lexicographically?
Correct Answer: (C) strcmp().
33. What does strcmp() return if the first string is lexicographically smaller than the second?
Correct Answer: (C) A negative integer.
34. What will strlen("") return?
Correct Answer: (C) 0.
35. Which string function returns the concatenated string?
Correct Answer: (C) strcat().
36. What does strcpy(dest, src) do?
Correct Answer: (B) Copies src to dest.
37. If char s[] = "apple";, what will strlen(s) return?
Correct Answer: (B) 5.
38. What will be the result of strcmp("apple", "apple")?
Correct Answer: (A) 0.
39. Which function is used to concatenate two strings in C?
Correct Answer: (B) strcat().
40. What happens if strcmp() finds two identical strings?
Correct Answer: (C) Returns 0.
41. What does a pointer store in C?
Correct Answer: (B) Address of a variable.
42. What is the primary use of pointers in C?
Correct Answer: (B) To store memory addresses.
43. What does the * symbol represent in pointer declaration?
Correct Answer: (C) Dereferencing the pointer.
44. How do you declare a pointer to a string in C?
Correct Answer: (A) char *ptr.
45. What will char *ptr = "Hello"; store in ptr?
Correct Answer: (C) The address of the string.
46. Which of the following is true about pointers and arrays?
Correct Answer: (C) Arrays store values, pointers store addresses.
47. How do you access the value of a variable through a pointer?
Correct Answer: (B) By using *ptr.
48. What will *(ptr + 2) access in a string pointer ptr pointing to "Hello"?
Correct Answer: (C) Third character.
49. How can you move to the next character in a string using a pointer?
Correct Answer: (A) ptr++.
50. Which of the following function uses pointers to pass variables by reference?
Correct Answer: (B) scanf().
51. How does char *ptr = str; work in C?
Correct Answer: (B) Assigns the address of str to ptr.
52. What is the output of the following code?
char str[6] = "Hello";
char *ptr = str;
printf("%c", *(ptr+1));
Correct Answer: (B) e.
53. What does the expression ptr[2] mean if ptr is a pointer to a string?
Correct Answer: (C) Accesses the third character of the string.
54. What does char *ptr = "Hello"; do in memory?
Correct Answer: (B) Points ptr to the address of "Hello".
55. Which operator is used to get the address of a variable in C?
Correct Answer: (B) &.
56. What is the output of this code?
char str[6] = "World";
char *ptr = str;
while(*ptr != '\0') {
printf("%c", *ptr);
ptr++;
}
Correct Answer: (A) World.
57. Which function can dynamically allocate memory for a string?
Correct Answer: (A) malloc().
58. Which of the following is true about pointer arithmetic in C?
Correct Answer: (A) ptr++ increments the pointer to point to the next element.
59. What does *(ptr++) do?
Correct Answer: (B) Moves the pointer to the next memory location after dereferencing.
60. Why is it necessary to use free() with dynamically allocated memory?
Correct Answer: (A) To prevent memory leakage.